container_aria

my file learn about tech container (docker, podman, kubernetes)


Project maintained by ariafatah0711 Hosted on GitHub Pages — Theme by mattgraham

env variable

env

ENV key=value
ENV key1=value1 key2=value2

contoh

FROM golang:1.18-alpine

ENV APP_PORT=8080

RUN mkdir app
COPY main.go app/

EXPOSE ${APP_PORT}

CMD go run app/main.go

main.go

package main

import (
    "fmt"
    "net/http"
    "os"
)

func main() {
    port := os.Getenv("APP_PORT")
    fmt.Println("Run app in port : " + port)
    http.HandleFunc("/", HelloServer)
    http.ListenAndServe(":" + port, nil)
}

func HelloServer(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, World!")
}